package top.lcm889.nowcoder.top;

import java.util.HashMap;

/**
 * @author Coder-lcm
 * @date 2021/2/24
 */
public class NC61_两数之和 {
    public static int[] twoSum (int[] numbers, int target) {
        HashMap<Integer, Integer> m = new HashMap<>();
        for (int i = 0; i < numbers.length; i++) {
            int cur = numbers[i];
            if (m.containsKey(target - cur)) {
               return new int[]{m.get(target - cur) + 1, i + 1};
            }
            m.put(cur, i);
        }
        return new int[0];
    }

    public static void main(String[] args) {
        int[] res = twoSum(new int[]{3, 2, 4}, 6);
        for (int i = 0; i < res.length; i++) {
            System.out.println(res[i]);
        }
    }
}
